package com.org.beauty.salon.controller;


import com.github.pagehelper.PageInfo;
import com.org.beauty.salon.entity.User;
import com.org.beauty.salon.request.QueryByConditionRequest;
import com.org.beauty.salon.service.IUserService;
import com.org.beauty.salon.utils.CopyUtil;
import com.org.beauty.salon.utils.WebResult;
import com.org.beauty.salon.vo.UserVo;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;

/**
 * <p>
 * 用户信息前端控制器
 * </p>
 *
 * @author zhangyanbin
 * @since 2020-07-27
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    /**
     * 功能描述: 根据用户ID查询用户信息
     *
     * @author zhangyanbin
     * @date 2020/8/26 14:29
     **/
    @ApiOperation(value = "根据用户ID查询用户信息", notes = "查询接口")
    @PostMapping("/getByUserId")
    public CompletableFuture<WebResult<UserVo>> getByUserId(@RequestParam Long userId) {
        return CompletableFuture.supplyAsync(() -> {
            User user = userService.getByUserId(userId);
            UserVo userVo = CopyUtil.copy(user, UserVo.class);
            return WebResult.successData(userVo);
        });
    }

    /**
     * 功能描述: 根据用户手机号查询用户信息
     *
     * @author zhangyanbin
     * @date 2020/8/26 17:10
     **/
    @ApiOperation(value = "根据用户手机号查询用户信息", notes = "查询接口")
    @PostMapping("/getByPhone")
    public CompletableFuture<WebResult<UserVo>> getByPhone(@RequestParam String phone) {
        return CompletableFuture.supplyAsync(() -> {
            User user = userService.getByPhone(phone);
            UserVo userVo = CopyUtil.copy(user, UserVo.class);
            return WebResult.successData(userVo);
        });
    }

    /**
     * 功能描述: 根据条件查询用户分页列表
     *
     * @author zhangyanbin
     * @date 2020/8/26 17:24
     **/
    @ApiOperation(value = "根据条件查询用户分页列表", notes = "查询接口")
    @PostMapping("/listByCondition")
    public CompletableFuture<PageInfo<UserVo>> listByCondition(@RequestParam QueryByConditionRequest request) {
        return CompletableFuture.supplyAsync(() -> {
            PageInfo<UserVo> userVoPageInfo = userService.listByCondition(request);
            return userVoPageInfo;
        });
    }


}
